<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<ul class="breadcrumb panel">
    <li><a href="javascript:backMainFun();"><i class="fa fa-home"></i> 首页</a></li>
    <li class="active">日志管理</li>
</ul>

<div class="panel">
    <div class="panel-body">
        <form action="" onsubmit="return false;">
            <div class="row">
                <div class="col-xs-3">
                    <div class="form-group marBN">
                        <div class="iconic-input">
                            <i class="fa fa-user"></i>
                            <input type="text" class="form-control" id="query_content" name="query_content" placeholder="按内容查找">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <button id="searchBtn" type="submit" class="btn btn-success"><i class="glyphicon glyphicon-search"></i> 查找</button>
                    <button type="reset" class="btn btn-warning"><i class="fa fa-trash-o"></i> 清空</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="panel">
    <header class="panel-heading">
        日志列表
    </header>
    <div class="panel-body">
        <table id="table1"
               data-toggle="table"
               data-classes="table table-hover"
               data-sort-order="asc"
               data-method="get"
               data-data-type="json"
               data-pagination="true"
               data-show-columns="true"
               data-minimum-count-columns="3"
               data-page-size="10"
               data-locale="zh-CN"
               data-striped="true"
        ></table>
    </div>
</div>

<script>

    $('#searchBtn').click(function(){
        $("#table1").bootstrapTable('refreshOptions',
                {
                    pagination: true,
                    dataShowToggle: true,
                    url: "${ctx}/log/getLogList",
                    queryParams: function (params) {
                        return $.extend({}, params, {
                            query_content: $('#query_content').val()
                        });
                    }
                });
    });


    $("#table1").bootstrapTable({
        contentType: "application/x-www-form-urlencoded",
        method: 'post',
        sidePagination: 'server',
        pagination: true,
        dataShowToggle: true,
        url:"${ctx}/log/getLogList",
        columns: [
            {
                field: 'num',
                title: '序号',
                formatter:function (value, row, index) {
                    if($('.pagination').find('li.active').find('a').text()){
                        var numbers = parseInt([parseInt($('.pagination').find('li.active').find('a').text())-1]* parseInt($('.page-size').text()) )+ parseInt(index+1);
                        return [
                            numbers
                        ].join('') ;
                    }else{
                        return [
                            index+1
                        ].join('') ;
                    }

                }
            }, {
                field: 'content',
                title: "内容"
            }, {
                field: 'iP',
                title: "操作IP"
            }, {
                field: 'cdate',
                title: "操作时间",
                formatter:formatterDate

            }]
//            },{
//                field: 'log_id',
//                title: '操作',
//                formatter:option
//            }]
    });
    function formatterDate(value) {
        var dateObj = new Date(value);
        return dateObj.getFullYear() + '-' + (dateObj.getMonth() + 1) + '-' + dateObj.getDate() + ' '+
                dateObj.getHours()+":"+dateObj.getMinutes()+":"+dateObj.getSeconds();
    }
    function option(value,row){
        return [
            '<button class="btn btn-xs btn-danger" onclick="delFun(\''+value+'\')"><i class="glyphicon glyphicon-remove"></i> 删除</button>',
        ].join('');
    }
</script>